import mysql from 'mysql'
import { dbConfig } from '../serviceConfig'
// 创建数据池
const pool = mysql.createPool(dbConfig)
export default (sql: string, values?: any) => {
  return new Promise<any>((resolve, reject) => {
    pool.getConnection((err, connection) => {
      if (err) {
        reject(err)
      } else {
        connection.query(sql, values, (err, rows) => {
          if (err) {
            reject(err)
          } else {
            resolve(rows)
          }
          connection.release()
        })
      }
    })
  })
}
